#include <iostream>
#include <Windows.h>
#include <string>
 
HWND PerWindow = NULL;
 
int main(void) {
	char title[256];
 
	while (1) {
		HWND window = GetForegroundWindow();  //获取当前窗口
		if (window != PerWindow) {
			PerWindow = window;
			GetWindowText(window, title, 256);
			printf("\r\r当前活动窗口为:%s\r\n", title);
 
		}
		for (int key = '0'; key <= '9'; key++) {
			
			if (GetAsyncKeyState(key)&0x8000) {
				printf("当前键盘输入: %c\n", key);
 
				while (GetAsyncKeyState(key) & 0x8000) {
 
					Sleep(1);
				}
			}
			
		}
 
	}
 
	return 0;
}